package com.opencart.web.validator;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.opencart.domain.Category;

@Component(value = "categoryValidator")
public class CategoryValidator implements Validator {

	public boolean supports(Class<?> clazz) {
		return Category.class.isAssignableFrom(clazz);
	}

	public void validate(Object target, Errors errors) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name",
				"category.name.required", "Category name is required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description",
				"category.description.required", "Description is required");
	}

}
